let host = "http://127.0.0.1:1337";

let ipts = document.querySelectorAll(".alterpwd input");
let token = localStorage.getItem("token");

let btn = document.querySelector(".btn");

changeColor(ipts,btn);
btn.onclick = async function(e) {
    e.preventDefault();
    let regUrl = host + "/api/v1/user/update_pwd";
    let data = {oldPassword:ipts[0].value,password:ipts[1].value};
    let {oldPassword,password} =  data;
    if(oldPassword.trim()=="" || password.trim()=="") {
        alert("请填充两个输入框的内容");
    } else {
        axios.defaults.headers.common["token"] = token;
        let p1 = await axios.put(regUrl,data);
        if(p1.data.code==1) {
            console.log("修改成功");
            window.open("subsuccespwd.html");
            localStorage.setItem("token",p1.data.data);
        } else {
            console.log("修改失败");
        }
    }
}